package demo.ftp.pool2;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.GenericObjectPool;

/**
 * 组合形式，防止注册SPRING时报Spring中MXBean已注册问题
 * 
 * @author hanjy
 * 
 *         <link>https://blog.csdn.net/yiifaa/article/details/73243598?utm_source=blogxgwz1</link>
 */
public class FTPClientPoolB {

    private final GenericObjectPool<FTPClient> pool;

    public FTPClientPoolB(PooledObjectFactory<FTPClient> factory) {
        this.pool = new GenericObjectPool<>(factory);
    }

    public FTPClient borrowObject(long borrowMaxWaitMillis) throws Exception {
        return pool.borrowObject(borrowMaxWaitMillis);
    }

    public void returnObject(final FTPClient ftp) {
        pool.returnObject(ftp);
    }

}
